package main

import (
	"fmt"
	"sort"
	"waterbeside/ltt/src/helper"
)

func minimumAbsDifference(arr []int) [][]int {
	sort.Ints(arr)
	minDiff := 1<<32 - 1
	var ans [][]int
	for i := 1; i < len(arr); i++ {
		diff := arr[i] - arr[i-1]
		if diff < minDiff {
			minDiff = diff
			ans = [][]int{{arr[i-1], arr[i]}}
		} else if diff == minDiff {
			ans = append(ans, []int{arr[i-1], arr[i]})
		}
	}
	return ans
}

func minimumAbsDifference2(arr []int) [][]int {
	helper.QuickSort(arr, 0, len(arr)-1)
	minDiff := arr[1] - arr[0]
	var ans = [][]int{{arr[0], arr[1]}}
	for i := 2; i < len(arr); i++ {
		diff := arr[i] - arr[i-1]
		if diff < minDiff {
			minDiff = diff
			ans = [][]int{{arr[i-1], arr[i]}}
		} else if diff == minDiff {
			ans = append(ans, []int{arr[i-1], arr[i]})
		}
	}
	return ans
}

func main() {
	arr := []int{4, 2, 1, 3}
	fmt.Println(minimumAbsDifference2(arr))
}
